/*
 * Copyright 2009 SHOP.COM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.shop.opensocial.mediated.shindig.factories;

import com.shop.opensocial.mediated.types.AddressMediator;
import org.apache.shindig.social.opensocial.model.Address;
import org.apache.shindig.social.core.model.AddressImpl;

/**
 * Factory for converting between Mediator type and Shindig type
 *
 * @author Jordan Zimmerman
 */
public class AddressMediatorFactory extends GenericMediatorFactory<Address, AddressMediator>
{
	public static final GenericMediatorFactoryBase<Address, AddressMediator>		i = new AddressMediatorFactory();

	@Override
	protected Address internalMake(AddressMediator ma)
	{
		Address		a = new AddressImpl();
		a.setCountry(ma.getCountry());
		a.setFormatted(ma.getFormatted());
		a.setLatitude(ma.getLatitude());
		a.setLocality(ma.getLocality());
		a.setLongitude(ma.getLongitude());
		a.setPostalCode(ma.getPostalCode());
		a.setPrimary(ma.getPrimary());
		a.setRegion(ma.getRegion());
		a.setStreetAddress(ma.getStreetAddress());
		a.setType(ma.getType());

		return a;
	}

	@Override
	protected AddressMediator internalUnmake(final Address c)
	{
		return new AddressMediator()
		{
			@Override
			public String getCountry()
			{
				return c.getCountry();
			}

			@Override
			public Float getLatitude()
			{
				return c.getLatitude();
			}

			@Override
			public String getLocality()
			{
				return c.getLocality();
			}

			@Override
			public Float getLongitude()
			{
				return c.getLongitude();
			}

			@Override
			public String getPostalCode()
			{
				return c.getPostalCode();
			}

			@Override
			public String getRegion()
			{
				return c.getRegion();
			}

			@Override
			public String getStreetAddress()
			{
				return c.getStreetAddress();
			}

			@Override
			public String getType()
			{
				return c.getType();
			}

			@Override
			public String getFormatted()
			{
				return c.getFormatted();
			}

			@Override
			public Boolean getPrimary()
			{
				return c.getPrimary();
			}
		};
	}

	private AddressMediatorFactory()
	{
	}
}
